package com.gdgk.shop.api.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.InputStream;

@Configuration
@AllArgsConstructor
public class WxPayConfiguration {
    private WxPayProperties properties;

//    @Bean
//    @ConditionalOnMissingBean
//    public WxPayService wxMiniPayService() {
//        WxPayConfig payConfig = new WxPayConfig();
//        payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
//        payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
//        payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
//        payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
//        // 可以指定是否使用沙箱环境
//        payConfig.setUseSandboxEnv(false);
//
//        WxPayService wxPayService = new WxPayServiceImpl();
//        wxPayService.setConfig(payConfig);
//        return wxPayService;
//    }
//    @Bean
//    @ConditionalOnMissingBean
//    public JsapiServiceExtension wxMiniPayService() throws IOException {
////        System.out.println(this.properties.getPrivateKey());
//        Config config = new RSAAutoCertificateConfig.Builder()
//                        .merchantId(this.properties.getMchId())
//                        //.privateKeyFromPath(this.properties.getKeyPath())
//                        .privateKey(this.properties.getPrivateKey())
//                        .merchantSerialNumber(this.properties.getSerial())
//                        .apiV3Key(this.properties.getApiV3Key())
//                        .build();
//        // 构建service
//        JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
//        return service;
//    }

}
